﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PreventChess
{
    public partial class ChessmanButton : Button
    {

        #region 枚举类型

        public enum ChessmanArrowColor
        {
            RED,
            ORANGE,
            YELLOW,
            GREEN,
            BLUE,
            PURPLE,
        }
        public enum ChessmanArrowType
        {
            ONE,
            TWO_45,
            TWO_90,
            TWO_135,
            TWO_180,
            THREE_45,
            THREE_90,
            FOUR,
            JUMP

        }
        #endregion


        public ChessmanButton()
        {
            InitializeComponent();
      
            this.Text = "";
            this.Height = this.Width;

            //this.ImageAlign = ContentAlignment.MiddleCenter;
            this.BackgroundImageLayout = ImageLayout.Stretch;
            this.Font = new Font("楷体", 12);
            //this.Padding = Padding.Empty;
            this.Margin = new Padding(0); //  Margin赋值方法
            this.FlatStyle = FlatStyle.Flat;
            this.FlatAppearance.BorderColor = Color.White;
            this.FlatAppearance.BorderSize = 1;
            this.FlatAppearance.MouseDownBackColor = Color.DimGray;
            //this.FlatAppearance.MouseOverBackColor = Color.White;
            this.TextAlign = ContentAlignment.BottomRight;
            this.Enter += this.Chessman_Enter;
            this.Leave += this.Chessman_Leave;
            this.Click += this.Chessman_Click;
            this.Enabled = false;
            
        }
         
        private void Chessman_Enter(object sender, EventArgs e)
        {
            this.FlatAppearance.BorderColor = Color.Black;
            
        }

        private void Chessman_Leave(object sender, EventArgs e)
        {
            this.FlatAppearance.BorderColor = Color.White;
           // FrmChessBoard.active_chess_btn = null;

        }

        private void Chessman_Click(object sender, EventArgs e)
        {
            FrmChessBoard.active_chess_btn = (ChessmanButton)sender;
           // MessageBox.Show(FrmChessBoard.active_chess_btn.arrowType.ToString());

        }


        #region 控件属性

        private ChessmanArrowColor arrowColor = ChessmanArrowColor.RED;
        [Category("棋子按钮属性")]
        [Description("颜色")]
        public ChessmanArrowColor ArrowColor
        {
            get { return arrowColor; }
            set
            {
                arrowColor = value;
                SetChessmanColor(arrowColor);
                this.Invalidate();

            }
        }


       
        private ChessmanArrowType arrowType = ChessmanArrowType.ONE;

        [Category("棋子按钮属性")]
        [Description("样式")]
        public ChessmanArrowType ArrowType
        {
            get { return arrowType; }
            set
            {
                arrowType = value;
                SetChessmanType(arrowType);
                this.Invalidate();

            }
        }


        private int amount = 0;

        [Category("棋子按钮属性")]
        [Description("数量")]
        public int Amount
        {
            get { return amount; }
            set
            {
                amount = value;
                if(amount == 0)
                {
                    this.BackColor = Color.LightGray;
                    this.Enabled = false;
                    this.Text = "";
                }
                else if(amount == 1)
                {
                    ChessmanArrowColor temp_color = arrowColor;
                    this.ArrowColor = temp_color;
                    this.Enabled = true;
                    this.Text = "";
                }
                else
                {
                    ChessmanArrowColor temp_color = arrowColor;
                    this.ArrowColor = temp_color;
                    this.Enabled = true;
                    this.Text = "x" + amount;
                }
                this.Invalidate();

            }
        }



 
        #endregion

        void SetChessmanColor(ChessmanArrowColor color)
        {
            switch (color)
            {
                case ChessmanArrowColor.RED:
                    this.BackColor = Color.Red;
                    break;
                case ChessmanArrowColor.BLUE:
                    this.BackColor = Color.DeepSkyBlue;

                    break;
                case ChessmanArrowColor.PURPLE:
                    //this.BackColor = Color.Pink;
                    this.BackColor = Color.MediumPurple;

                    break;
                case ChessmanArrowColor.YELLOW:
                    this.BackColor = Color.Khaki;

                    break;
                case ChessmanArrowColor.GREEN:
                    this.BackColor = Color.Green;

                    break;
                case ChessmanArrowColor.ORANGE:
                    this.BackColor = Color.Orange;

                    break;
                default:
                    break;
            }
        }

        void SetChessmanType(ChessmanArrowType type)
        {
            switch (type)
            {
                case ChessmanArrowType.ONE:
                    this.BackgroundImage = Properties.Resources.w_1;
                    break;
                case ChessmanArrowType.TWO_45:
                    this.BackgroundImage = Properties.Resources.w_2_45;

                    break;
                case ChessmanArrowType.TWO_90:
                    this.BackgroundImage = Properties.Resources.w_2_90;

                    break;
                case ChessmanArrowType.TWO_135:
                    this.BackgroundImage = Properties.Resources.w_2_135;

                    break;
                case ChessmanArrowType.TWO_180:
                    this.BackgroundImage = Properties.Resources.w_2_180;

                    break;
                case ChessmanArrowType.THREE_45:
                    this.BackgroundImage = Properties.Resources.w_3_45;

                    break;
                case ChessmanArrowType.THREE_90:
                    this.BackgroundImage = Properties.Resources.w_3_90;

                    break;
                case ChessmanArrowType.FOUR:
                    this.BackgroundImage = Properties.Resources.w_4_90;

                    break;
                case ChessmanArrowType.JUMP:
                    this.BackgroundImage = Properties.Resources.w_jump;

                    break;
                default:
                    break;
            }

        }
    
    }
}
